import { IDomEditor, SlateDescendant, SlateElement } from '@wangeditor/editor';
import {TagElement} from "./types";

/**
 * @description 解析tag元素 HTML 到编辑器
 * @param elem
 * @param children
 * @param editor
 */
function parseTagEleToHtml(elem: Element, children: SlateDescendant[], editor: IDomEditor): TagElement {
  //获取元素value
  const value = elem.getAttribute("data-value") || "";
  const className = elem.getAttribute("data-class-name") || "1";
  return {
    type: "tag",
    value,
    className: className,
    children: [{
      text: ""
    }]
  };
}

const parseElemHtml = {
  selector: "span[data-w-e-type='tag']",
  parseElemHtml: parseTagEleToHtml
};

export default parseElemHtml;
